﻿#region File Description

/* Camera.cs
 * 
 * Author: smc_gamer
 * Date: Sat 10/8/2011
 * Revision 1
 * 
 * A camera class that handles level scrolling.
 * It also does zoom and rotation.  Credit to
 * David Amador (http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/)
 * for the information and code.
 * 
 */

#endregion

using System;

using Microsoft.Xna.Framework;

namespace SmlEngine.Sprites.Camera
{
    public sealed class Camera2D
    {
        private float zoom;
        private Matrix transform;

        public float Zoom
        {
            get { return zoom; }
            set
            { 
                if (value > 0.1f) 
                    zoom = value; 
                else 
                    zoom = 0.1f; 
            }
        }
        public float Rotation { get; set; }
        public Vector2 Position { get; set; }

        public Camera2D()
        {
            Zoom = 1.0f;
            Rotation = 0.0f;
            Position = Vector2.Zero;
        }

        public void Move(Vector2 amount)
        {
            Position += amount;
        }

        public Matrix GetTransformation()
        {
            transform = Matrix.CreateTranslation(-Position.X, -Position.Y, 0) * 
                        Matrix.CreateScale(Zoom) *
                        Matrix.CreateRotationZ(Rotation);

            return transform;
        }
    }
}
